package com.paddyi.commons.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.assertj.core.internal.bytebuddy.asm.Advice;

/**
 * @program: paddyi
 * @description: 发送短信验证码-阿里云版本
 * @author: paddy
 * @create: 2019-08-02 00:45
 **/
public class SendSmsUtil {
    private final static String AccessKey = "LTAIGikQw4inZa5Z";
    private final static String AccessKeySecret = "H8XLsrP0gsUMJCdfyNrJJ67Ds6JNTh";
    private final static String DOMAIN = "dysmsapi.aliyuncs.com";

    public static String SendSms(String phoneNumbers,String code) {
        DefaultProfile profile = DefaultProfile.getProfile("default", AccessKey, AccessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain(DOMAIN);
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "default");
        request.putQueryParameter("PhoneNumbers", phoneNumbers);
        request.putQueryParameter("SignName", "PADDYI");
        request.putQueryParameter("TemplateCode", "SMS_171851604");
        request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            return response.getData();
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return "";
    }

}
